package com.littleHan.brushQuestions.web.start.controller;

import com.alibaba.fastjson.JSON;
import com.littleHan.brushQuestions.common.Result;
import com.littleHan.brushQuestions.exception.FailedToLoadException;
import com.littleHan.brushQuestions.web.frontPage.dao.FrontPageDao;
import com.littleHan.brushQuestions.web.start.pojo.GeneralUser;
import com.littleHan.brushQuestions.web.start.pojo.vo.TopicVo;
import com.littleHan.brushQuestions.web.start.service.LastIndexService;
import com.littleHan.brushQuestions.web.userCenter.pojo.Announcement;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/lastIndex")
public class LastIndexController {

    @Autowired
    private LastIndexService lastIndexService;

    @RequestMapping(value = "/testIsLoginJ", method = RequestMethod.POST)
    public String testIsLogin(HttpServletRequest request) {
        String info = lastIndexService.testIsLogin(request);
        return info;
    }

    /**
     * 获取站长信息
     *
     * @return 是否获取站长信息成功
     * @throws FailedToLoadException
     */
    @RequestMapping(value = "/getWebAdminJ", method = RequestMethod.GET)
    public String getWebAdminInfo() throws FailedToLoadException {
        GeneralUser generalUser = lastIndexService.getWebAdminInfo();
        return JSON.toJSONString(new Result().setCode(200).setMessage("获取站长信息成功").setData(generalUser));
    }

    /**
     * 获取5道题目
     *
     * @return 是否获取题目成功
     * @throws FailedToLoadException
     */
    @RequestMapping(value = "/getTopicJ", method = RequestMethod.POST)
    public String getTopic() throws FailedToLoadException {
        List<TopicVo> topicVoList = lastIndexService.getTopic();
        return JSON.toJSONString(new Result().setCode(200).setMessage("获取题目成功").setData(topicVoList));
    }

    /**
     * 获取网站公告
     *
     * @return
     */
    @GetMapping("/getAnnouncementListJ")
    public String getAnnouncementList() {
        List<Announcement> list = lastIndexService.getAnnouncementList();
        return JSON.toJSONString(new Result().setCode(200).setMessage("获取网站公告成功").setData(list));
    }

    /**
     * 获取有获赞榜单-前五名，降序
     *
     * @return
     */
    @GetMapping("/getCommentLikeMaxList")
    public String getCommentLikeMaxList() {
        return JSON.toJSONString(new Result().setCode(200).setMessage("获取获赞排行榜成功").setData(lastIndexService.getCommentLikeMaxList()));
    }
}
